package com.xmtlxx.system.domain;

import com.xmtlxx.common.core.domain.BaseEntity;
import com.xmtlxx.common.utils.StringUtils;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * OSS对象存储对象
 *
 * @author xmtlxx
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sys_oss")
public class SysOss extends BaseEntity {

    /**
     * 对象存储主键
     */
    @TableId(value = "oss_id", type = IdType.AUTO)
    private Long ossId;

    /**
     * 文件名
     */
    private String fileName;

    /**
     * 原名
     */
    private String originalName;

    /**
     * 文件后缀名
     */
    private String fileSuffix;

    /**
     * URL地址
     */
    private String url;

    /**
     * 服务商
     */
    private String service;

    /**
     * 租户(企业)ID
     */
    @ApiModelProperty(value = "租户(企业)ID")
    private Long tenantId;

    /**
     * 业务类型
     */
    @ApiModelProperty(value = "业务类型")
    private String buss;

    /**
     * 对象ID
     */
    @ApiModelProperty(value = "对象ID")
    private String objid;

    @ApiModelProperty(value = "缩略图")
    @TableField(exist = false)
    private String thumbnail;

    public String getThumbnail() {
        if(StringUtils.isBlank(fileName)){
            return null;
        }
        return fileName.substring(0,fileName.lastIndexOf("/"))+"/thumbnail_"+fileName.substring(fileName.lastIndexOf("/")+1,fileName.length());
    }
}
